/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-02-17
 * Time: 12:17
 */
class Solution15_1 {
    public int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        int[] ret = new int[n];
        ret[n-1] = 0;
        for(int i = 0 ; i < n-1 ; i++){
            int curNum = temperatures[i];
            int count = 0;
            for(int j = i+1 ; j < n ; j++){
                int moveNum = temperatures[j];
                if(moveNum > curNum){
                    count++;
                    break;
                }else if(moveNum < curNum){
                    count++;
                }else{
                    count++;
                }
                if(j == n-1){
                    count = 0;
                }
            }
            ret[i] = count;
        }
        return ret;
    }
}
class Solution15 {
    public int[] dailyTemperatures(int[] t) {
        //太妙了
        int n = t.length;
        int[] result = new int[n];
        for(int i = n-2 ; i >= 0 ; i--){
            int curt = t[i];
            for(int j = i + 1 ; j < n ; ){
                int movet = t[j];
                if(curt < movet){
                    result[i] = j - i;
                    break;
                }else if(result[j] == 0){//这里就是curt大于等于movet，并且movet后面没有比movet更高的温度了
                    result[i] = 0;
                    break;
                }else{
                    j += result[j];
                }
            }
        }
        return result;
    }
}
public class Test15 {
}
